//! YoshiFlowMain.debug.js
//

(function() {

Type.registerNamespace('YoshiFlowMain');

////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.FeaturesPage

YoshiFlowMain.FeaturesPage = function YoshiFlowMain_FeaturesPage() {
    /// <field name="_featuresDb$6" type="Object" static="true">
    /// </field>
    /// <field name="_outer$6" type="jQueryObject">
    /// </field>
    YoshiFlowMain.FeaturesPage.initializeBase(this);
    new Await().addAw(ss.Delegate.create(this, this.basicBuildAw), GamesTheme.pageTitle).commit();
}
YoshiFlowMain.FeaturesPage.prototype = {
    _outer$6: null,
    
    refreshAw: function YoshiFlowMain_FeaturesPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        this._outer$6 = $('<div/>').appendTo(this.pageCluster).addClass(YoshiFlowMain.FeaturesPage._featuresDb$6['Class']);
        new Await().addAw(EditListHtml.showHtmlListAw, YoshiFlowMain.FeaturesPage._featuresDb$6, this._outer$6).addDx(ss.Delegate.create(this, function() {
            $('h2,li', this._outer$6).click(ss.Delegate.create(this, function(e) {
                DomElement.cancelEvent(e);
                new Await().addAw(EditListHtml.aw, $(e.target)).handleDl(Exceptions.userCancelled, Await.finishAw).addDl(ss.Delegate.create(this, function(aw) {
                    if (aw.get_item('changed')) {
                        FileBlobBase.putBlobAw(aw, EditListHtml.scoopData(this._outer$6), YoshiFlowMain.FeaturesPage._featuresDb$6);
                    }
                })).handleDl(Exceptions.fileIsNewer, function(aw) {
                    new Ask().okAw(aw, ThemeBase.isCheckedOut);
                }).commit();
            }));
            $('.SectionJar', this._outer$6).prepend(this.duplicateBtn({ top: '3px', left: '-26px' }, ss.Delegate.create(this, this.dupeSectAw))).append(this.deleteBtn({ top: '3px', right: '-20px' }));
            $('.ItemJar', this._outer$6).prepend(this.duplicateBtn({ top: '0px', left: '-86px' }, ss.Delegate.create(this, this.dupeItemAw))).append(this.deleteBtn({ top: '0px', right: '-40px' }));
        })).commit(awp);
    },
    
    deleteAw: function YoshiFlowMain_FeaturesPage$deleteAw(awp, elToDel) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="elToDel" type="jQueryObject">
        /// </param>
        elToDel.remove();
        awp.done();
    },
    
    deleteBtn: function YoshiFlowMain_FeaturesPage$deleteBtn(options) {
        /// <param name="options" type="Object">
        /// </param>
        /// <returns type="jQueryObject"></returns>
        var css = {};
        css['position'] = (options['position'] || 'absolute');
        css['top'] = (options['top'] || '0px');
        css['right'] = (options['right'] || '-20px');
        if (Object.keyExists(options, 'css')) {
            $.extend(css, options['css']);
        }
        return $("<span class='SimpleDeleteBtn'/>").css(css).attr('title', ThemeBase.deleteBtnTitle).html('-').click(ss.Delegate.create(this, function(e) {
            DomElement.cancelEvent(e);
            new Await().addAw(ss.Delegate.create(new Ask(), new Ask().okCancelAw), ThemeBase.forSure).addAw(DomElement.requireResultAw, true).addAw(ss.Delegate.create(this, this.deleteAw), $(e.target).closest('.Jar')).handleDl(Exceptions.userCancelled, Await.abortAw).addDl(ss.Delegate.create(this, function(aw) {
                FileBlobBase.putBlobAw(aw, EditListHtml.scoopData(this._outer$6), YoshiFlowMain.FeaturesPage._featuresDb$6);
            })).commit();
        }));
    },
    
    duplicateBtn: function YoshiFlowMain_FeaturesPage$duplicateBtn(options, action) {
        /// <param name="options" type="Object">
        /// </param>
        /// <param name="action" type="System.Action`2">
        /// </param>
        /// <returns type="jQueryObject"></returns>
        var css = {};
        css['position'] = (options['position'] || 'absolute');
        css['top'] = (options['top'] || '0px');
        css['left'] = (options['left'] || '-20px');
        if (Object.keyExists(options, 'css')) {
            $.extend(css, options['css']);
        }
        return $("<span class='SimpleAddLineBtn'/>").css(css).html('+').attr('title', ThemeBase.addNewItemBtnTitle).click(ss.Delegate.create(this, function(e) {
            DomElement.cancelEvent(e);
            new Await().addAw(action, $(e.target).closest('.Jar')).handleDl(Exceptions.userCancelled, Await.abortAw).addDl(ss.Delegate.create(this, function(aw) {
                FileBlobBase.putBlobAw(aw, EditListHtml.scoopData(this._outer$6), YoshiFlowMain.FeaturesPage._featuresDb$6);
            })).commit();
        }));
    },
    
    dupeItemAw: function YoshiFlowMain_FeaturesPage$dupeItemAw(awp, el) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="el" type="jQueryObject">
        /// </param>
        el.clone(true, true).insertAfter(el).find('li').html('').click();
        awp.done();
    },
    
    dupeSectAw: function YoshiFlowMain_FeaturesPage$dupeSectAw(awp, el) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="el" type="jQueryObject">
        /// </param>
        var sect = el.clone(true, true).insertAfter(el);
        sect.find('.ItemJar').slice(1).remove();
        sect.find('li').html('');
        sect.find('h2').html('New topic').click();
        awp.done();
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.GamesPage

YoshiFlowMain.GamesPage = function YoshiFlowMain_GamesPage() {
    /// <field name="_outer$6" type="jQueryObject">
    /// </field>
    /// <field name="_worms$6" type="jQueryObject">
    /// </field>
    YoshiFlowMain.GamesPage.initializeBase(this);
    new Await().addAw(ss.Delegate.create(this, this.basicBuildAw), GamesTheme.pageTitle).commit();
}
YoshiFlowMain.GamesPage.prototype = {
    _outer$6: null,
    _worms$6: null,
    
    refreshAw: function YoshiFlowMain_GamesPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        this._outer$6 = $('<div/>').appendTo(this.pageCluster);
        this._worms$6 = $("<div style='position:absolute;top:0;left:0;width:100%;height:100%;opacity:.15'/>").prependTo('#PageContent').append($("<canvas style='width:100%;height:100%'/>"));
        new Await().addDx(ss.Delegate.create(this, function() {
            $("<a href='http://www.stumbleupon.com/su/2Laj6v/butchersworkshop.com/witr/' target='_blank'>Find the red game</a>").css({ 'margin-left': '50px', color: '#800' }).appendTo(this._outer$6);
            new EmotionalScale().appendTo(this._outer$6).prepend($('<h3/>').html('The Emotional Scale'));
            new Await().loadScript('Scripts/Worms/Worms.js').addDx(ss.Delegate.create(this, function() {
                $('canvas', this._worms$6).wormFill();
            })).commit();
        })).commit(awp);
    },
    
    destroy: function YoshiFlowMain_GamesPage$destroy() {
        $('canvas', this._worms$6).wormKill();
    },
    
    deleteAw: function YoshiFlowMain_GamesPage$deleteAw(awp, elToDel) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="elToDel" type="jQueryObject">
        /// </param>
        awp.done();
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.HomePage

YoshiFlowMain.HomePage = function YoshiFlowMain_HomePage() {
    YoshiFlowMain.HomePage.initializeBase(this);
    this.basicBuildAw(Await.get_asyncAw(), UserTheme.pageTitle);
}
YoshiFlowMain.HomePage.prototype = {
    
    refreshAw: function YoshiFlowMain_HomePage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var feed = $('<div/>').appendTo(this.pageCluster);
        new Await().addAw(FeedBubble.newAw, feed).commit(awp);
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.MagneticListPage

YoshiFlowMain.MagneticListPage = function YoshiFlowMain_MagneticListPage() {
    /// <field name="_cluster$6" type="MagBubble">
    /// </field>
    YoshiFlowMain.MagneticListPage.initializeBase(this);
    new Await().addAw(ss.Delegate.create(this, this.basicBuildAw), MagneticListPageTheme.pageTitle).commit();
}
YoshiFlowMain.MagneticListPage.prototype = {
    _cluster$6: null,
    
    destroy: function YoshiFlowMain_MagneticListPage$destroy() {
        if (this._cluster$6 != null) {
            this._cluster$6.destroy();
        }
    },
    
    refreshAw: function YoshiFlowMain_MagneticListPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addDx(ss.Delegate.create(this, function(aw) {
            this.destroy();
            this._cluster$6 = new MagBubble(aw);
            this._cluster$6.element.appendTo(this.pageCluster);
        })).commit(awp);
    },
    
    updatePage: function YoshiFlowMain_MagneticListPage$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
        this.topBar.updatePage(pu);
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.ProfilePage

YoshiFlowMain.ProfilePage = function YoshiFlowMain_ProfilePage() {
    /// <field name="_cluster$6" type="ProfileCluster">
    /// </field>
    YoshiFlowMain.ProfilePage.initializeBase(this);
    new Await().addAw(ss.Delegate.create(this, this.loadPageCssAw)).addAw(ss.Delegate.create(this, this.basicBuildAw), UserTheme.pageTitle).commit();
}
YoshiFlowMain.ProfilePage.prototype = {
    _cluster$6: null,
    
    refreshAw: function YoshiFlowMain_ProfilePage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addDx(ss.Delegate.create(this, function() {
            if (ss.isValue(this._cluster$6)) {
                this._cluster$6.destroy();
            }
        })).addDx(ss.Delegate.create(this, function() {
            this._cluster$6 = new ProfileCluster(null);
        })).addDx(ss.Delegate.create(this, function() {
            this._cluster$6.build();
        })).addDx(ss.Delegate.create(this, function() {
            this._cluster$6.element.appendTo(this.pageCluster);
        })).commit(awp);
    },
    
    updatePage: function YoshiFlowMain_ProfilePage$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
        this.topBar.updatePage(pu);
    },
    
    destroy: function YoshiFlowMain_ProfilePage$destroy() {
        if (this._cluster$6 != null) {
            this._cluster$6.destroy();
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.PublicPage

YoshiFlowMain.PublicPage = function YoshiFlowMain_PublicPage() {
    YoshiFlowMain.PublicPage.initializeBase(this);
    this.publicBuildAw(Await.get_asyncAw(), PublicPageTheme.pageTitle);
}
YoshiFlowMain.PublicPage.prototype = {
    
    refreshAw: function YoshiFlowMain_PublicPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        $('<h2/>').html('Hello <b>&#9788;</b>').css('margin', '50px').appendTo(this.pageCluster);
        var login = $('<div/>').appendTo(this.pageCluster);
        this.pageCluster.addClass(ThemeBase.currentPageClass);
        $("<p class='Login'/>").appendTo(login).html("Click here to log in using your Facebook account <img src='http://www.onewoundcare.com/files/7013/0023/9799/facebook-button.jpg' style='margin:0;padding:0;float:left'>").click(function() {
            Nsb.Storage.setLocal('Page', AllPages.homePage);
            new Await().addAw(ss.Delegate.create(Master.fbData, Master.fbData.authenticateAw)).addDx(function() {
                Master.GoPage(AllPages.homePage);
            }).commit();
        });
        new Await().commit(awp);
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.SearchPage

YoshiFlowMain.SearchPage = function YoshiFlowMain_SearchPage() {
    YoshiFlowMain.SearchPage.initializeBase(this);
    this.basicBuildAw(Await.get_asyncAw(), SearchTheme.pageTitle);
}
YoshiFlowMain.SearchPage.prototype = {
    
    refreshAw: function YoshiFlowMain_SearchPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var title = $('<h2/>').html('Search for a partner !!! :-)').css('margin', '50px').appendTo(this.pageCluster);
        new Await().addAw(ProfileData.searchForUsersAw, {}).addDx(ss.Delegate.create(this, function(aw) {
            var ids = aw.get_item(PkgBase.resultRx);
            var grid = $("<ul class='SearchResult'/>").insertBefore(title);
            var cnt = 0;
            var $enum1 = ss.IEnumerator.getEnumerator(ids);
            while ($enum1.moveNext()) {
                var id = $enum1.current;
                if (id === Master.profile.get_myId()) {
                    continue;
                }
                if (!Master.testing && Object.keyExists(ThemeBase.testUsers, id)) {
                    continue;
                }
                new Await().addAw(ProfileData.getUserByIdAw, id).addDx(ss.Delegate.create(this, function(aw2) {
                    var deg = (!((++cnt) % 2)) ? 365 : -365;
                    var usr = aw2.get_item(PkgBase.resultRx);
                    this.searchResult(usr).appendTo(grid).rotate({ animateTo: deg, duration: 800 });
                })).commit();
            }
        })).commit();
        new Await().addAw(SearchCluster.aw, title).commit(awp);
    },
    
    searchResult: function YoshiFlowMain_SearchPage$searchResult(usr) {
        /// <param name="usr" type="YoshiUser">
        /// </param>
        /// <returns type="jQueryObject"></returns>
        var item = $('<li/>');
        var photo = $("<div class='Photo'/>").appendTo(item);
        $('<img/>').appendTo(photo).attr('src', usr.get_photoUrl());
        $("<span class='Name'/>").appendTo(item).html(usr.alias);
        $("<span class='MessageBtn'/>").appendTo(item).html('send message').click(function(e) {
            Master.alivenessCheck(function() {
                EmailReply.sendPopupAw(Await.get_asyncAw(), usr, e);
            });
        });
        return item;
    },
    
    updatePage: function YoshiFlowMain_SearchPage$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
        if (this.topBar != null) {
            this.topBar.updatePage(pu);
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlowMain.EmailPage

YoshiFlowMain.EmailPage = function YoshiFlowMain_EmailPage() {
    /// <field name="_emailCluster$6" type="EmailCluster">
    /// </field>
    YoshiFlowMain.EmailPage.initializeBase(this);
    new Await().addAw(ss.Delegate.create(this, this.basicBuildAw), EmailTheme.pageTitle).commit();
}
YoshiFlowMain.EmailPage.prototype = {
    _emailCluster$6: null,
    
    refreshAw: function YoshiFlowMain_EmailPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addDx(ss.Delegate.create(this, function() {
            if (ss.isValue(this._emailCluster$6)) {
                this._emailCluster$6.destroy();
            }
        })).addDx(ss.Delegate.create(this, function() {
            this._emailCluster$6 = new EmailCluster(null);
        })).addDx(ss.Delegate.create(this, function() {
            this._emailCluster$6.build(true);
        })).addDx(ss.Delegate.create(this, function() {
            this._emailCluster$6.element.appendTo(this.pageCluster);
        })).commit(awp);
    },
    
    destroy: function YoshiFlowMain_EmailPage$destroy() {
        if (this._emailCluster$6 != null) {
            this._emailCluster$6.destroy();
        }
    }
}


YoshiFlowMain.FeaturesPage.registerClass('YoshiFlowMain.FeaturesPage', YoshiPage);
YoshiFlowMain.GamesPage.registerClass('YoshiFlowMain.GamesPage', YoshiPage);
YoshiFlowMain.HomePage.registerClass('YoshiFlowMain.HomePage', YoshiPage);
YoshiFlowMain.MagneticListPage.registerClass('YoshiFlowMain.MagneticListPage', YoshiPage);
YoshiFlowMain.ProfilePage.registerClass('YoshiFlowMain.ProfilePage', YoshiPage);
YoshiFlowMain.PublicPage.registerClass('YoshiFlowMain.PublicPage', YoshiPage);
YoshiFlowMain.SearchPage.registerClass('YoshiFlowMain.SearchPage', YoshiPage);
YoshiFlowMain.EmailPage.registerClass('YoshiFlowMain.EmailPage', YoshiPage);
YoshiFlowMain.FeaturesPage._featuresDb$6 = { PartitionKey: 'db/meta/features', RowKey: 'overview', Class: 'Features' };
})();

//! This script was generated using Script# v0.7.4.0
